package com.dhecp.project.business.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.utils.DateUtil;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.core.utils.ReadExcel;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.business.domain.ProductBasis;
import com.dhecp.project.business.domain.ProductXP;
import com.dhecp.project.business.service.ProductBasisService;
import com.dhecp.project.business.service.ProductXPService;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.common.domain.ModuleNidAndBid;
import com.dhecp.project.common.service.ModuleNidAndBidService;
import com.dhecp.project.hr.domain.OperateCompanyApply;
import com.dhecp.project.hr.service.OperateCompanyApplyService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;

/**
 * 选品 控制层 
 * @author DH-Xxj
 * @version 2022年7月22日
 */
@Controller
@RequestMapping("/business/productxp")
public class ProductXPController extends BaseModuleController{

	private String prefix = "business/productxp";
    private String moduleTable = ModuleTable.PRODUCT_XP;
    private String moduleTableGroup = ModuleTable.PRODUCT_XP_GROUP;
    
    @Autowired
    private ProductXPService businessService;
    
    @Autowired
    private ModuleNidAndBidService moduleNidAndBidService;
    
    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;
    
    @Autowired
    private OperateCompanyApplyService operateCompanyApplyService;
    
    @Autowired
    private ProductBasisService productBasisService;
    
    /**
     * 打开查询列表页
     * @param params
     * @return
     * @author DH-Xxj
     */
	@RequiresPermissions("business:productxp:view")
    @GetMapping()
    public ModelAndView listPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	params.put("entity", new ProductXP()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
    	params.put("prefix","business/business"); //页面路径
    	ModelAndView mv = this.openListPage(params);
    	mv.addObject("business", "productxp");
		return mv;
    }
	
	/**
     * 打开分组（整单）查询列表页
     * @param params
     * @return
     * @author DH-Xxj
     */
	@RequiresPermissions("business:productxp:view")
    @GetMapping("/listgrouppage")
    public ModelAndView listGroupPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTableGroup);
		params.put("moduleTableForButton", moduleTable);	//使用单据moduleTable的按钮状态
    	params.put("entity", new ProductXP()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
    	params.put("prefix","business/business"); //页面路径
    	ModelAndView mv = this.openListPage(params);
    	mv.addObject("business", "productxp/group");
		return mv;
    }
    
	/**
	 * 打开制单页
	 * @param nid 必要参数：单据编码（新增时传默认值 0 ，修改、查看时传单据实际值）
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions("business:productxp:view")
    @GetMapping("/edit")
    public ModelAndView editPage(@RequestParam Map<String, Object> params){  
		if (params.get("nid") == null || params.get("nid") == ""){
        	params.put("nid", "0");
		}      
    	params.put("moduleTable", moduleTable);
    	params.put("entity", new ProductXP()); //用于获取实体属性名取代对应字典字段名，解决大小写敏感问题
    	params.put("moduleUrl", prefix); //页面上级路径
    	params.put("prefix", prefix + "/productxp_edit"); //页面路径
    	
    	try{
            Map<String, Object> headData = new HashMap<String, Object>();		//表头的业务数据
//          SysModuleSet moduleSet = sysModuleSetService.queryModuleSet(params);//单据设置信息
            ProductXP businessData = businessService.queryFirstRecord(params);
        	if (businessData == null){ //未查询到对应单据，页面初始化值
        		ModuleNidAndBid moduleNidAndBid = moduleNidAndBidService.queryModuleNidAndBidInitial(params);
        		ProductXP businessDataNew = new ProductXP();
            	businessDataNew.setNid("0");
            	businessDataNew.setBid(moduleNidAndBid.getBid());
            	businessDataNew.setCreateTime(new Date());
            	businessDataNew.setCid(ShiroUtils.getMandatorCid());
            	businessDataNew.setCidName(ShiroUtils.getMandatorCidName());
            	businessDataNew.setbUser(ShiroUtils.getMandatorId());
            	businessDataNew.setbUserName(ShiroUtils.getMandatorName());
            	businessDataNew.setbDept(ShiroUtils.getMandatorDeptPath());
            	businessDataNew.setbDeptName(ShiroUtils.getMandatorDeptName());
            	businessDataNew.setbPosition(ShiroUtils.getMandatorPositionNameDa());
            	businessDataNew.setaUser(ShiroUtils.getUserId());
            	businessDataNew.setaUserName(ShiroUtils.getUserName());
            	businessDataNew.setaDept(ShiroUtils.getUserDeptPath());
            	businessDataNew.setaDeptName(ShiroUtils.getUserDeptName());
            	businessDataNew.setaPosition(ShiroUtils.getUserPositionNameDa());
        		headData = TypeUtils.entityToMap(businessDataNew);
        	}else{
        		headData = TypeUtils.entityToMap(businessData);
        	}
        	params.put("headData", headData); //表头的业务数据
        	
        	params.put("checkBox", "yes"); //生成表格gridColumns时包含复选
            ModelAndView mv = this.openEditPage(params);
            return mv;
    	}catch(Exception e){
//    		return this.gotoModelAndViewErrorPage(this.getExceptionMessage(e));	//简单信息
    		return this.gotoModelAndViewErrorPage(e.getMessage());	//详细信息
    	}

    }
    
    /**
     * 打开流转页
     * @param fType 必要参数：审核类型（flow_go：流转，flow_back：退回）
	 * @param infoMap 必要参数：非网格字段（包括所有显示和隐藏的字段），json格式字符串
     * @return
     * @author DH-Xxj
     */
	@RequiresPermissions("business:productxp:flow")
	@PostMapping("/flowpage")
	@ResponseBody
    public AjaxResult flowPage(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
		params.put("prefix", prefix);
//		String flowUrl = flowPageUrl(params);
//		return redirect(flowUrl);
		return openFlowPage(params);
    }
	
	/**
	 * 制单页 明细数据
	 * @param nid 必要参数：当前 单据编码
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions("business:productxp:list")
	@GetMapping("/listbynid")
    @ResponseBody
    public TableDataInfo listByNid(@RequestParam Map<String, Object> params){
		if (params.get("nid") == null || params.get("nid") == ""){
			return getDataTable(MessageUtils.message("module.error.lack.nid"));
		}
		params.put("moduleTable", moduleTable);
        List<ProductXP> list = new ArrayList<ProductXP>();
        try {
        	list = businessService.queryListByNid(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());            
        }
        return getDataTable(list);
    }

	/**
	 * 查询前一单NID、BID
	 * @param nid 必要参数：当前 单据编码
	 * @return AjaxResult (data.nid 前一单NID， data.bid 前一单BID)
	 * @author DH-Xxj
	 */
    @RequiresPermissions("business:productxp:view")
    @GetMapping("/lastnid")
    @ResponseBody
    public AjaxResult lastNid(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = businessService.queryLastNid(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

	/**
	 * 查询后一单NID、BID
	 * @param nid 必要参数：当前 单据编码
	 * @return AjaxResult (data.nid 后一单NID， data.bid 后一单BID)
	 * @author DH-Xxj
	 */
    @RequiresPermissions("business:productxp:view")
    @GetMapping("/nextnid")
    @ResponseBody
    public AjaxResult nextNid(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = businessService.queryNextNid(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

	/**
	 * 查询页 列表数据
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions("business:productxp:list")
	@GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
        List<ProductXP> list = new ArrayList<ProductXP>();
        try {
        	list = businessService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());            
        }
        return getDataTable(list);
    }
    
    /**
	 * 分组（整单）查询页 列表数据
	 * @param params
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions("business:productxp:list")
	@GetMapping("/group/list")
    @ResponseBody
    public TableDataInfo listGroup(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTableGroup);	//获取网格字段、查询条件字段、数据权限条件字段等
		params.put("jurisdictionModuleTable", moduleTable);	//使用单据moduleTable分配的数据权限
        List<ProductXP> list = new ArrayList<ProductXP>();
        try {
        	list = businessService.queryGroupList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());            
        }
        return getDataTable(list);
    }

    /**
     * 数据导出Excel
     * @param params
     * @return
     * @throws Exception
     * @author DH-Xxj
     */
    @RequiresPermissions("business:productxp:export")
    @Log(title = "选品数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
		params.put("moduleTable", moduleTable);
    	params.put("entity", new ProductXP()); 
    	
        List<ProductXP> list = businessService.queryList(params);
        
    	params.put("getFieldAttributesType", "export");
    	List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<ProductXP> util = new ExportExcelUtils<ProductXP>(moduleTable,new ProductXP());
        return util.exportExcel(list, fieldList, "选品数据", "export");
    }
    
    /**
     * 分组（整单）数据导出Excel
     * @param params
     * @return
     * @throws Exception
     * @author DH-Xxj
     */
    @RequiresPermissions("business:productxp:export")
    @Log(title = "选品整单数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/group/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult exportGroup(@RequestParam Map<String, Object> params) throws Exception {
		params.put("moduleTable", moduleTableGroup);	//获取网格字段、查询条件字段、数据权限条件字段等
		params.put("jurisdictionModuleTable", moduleTable);	//使用单据moduleTable分配的数据权限
    	params.put("entity", new ProductXP()); 
        
    	List<ProductXP> list = businessService.queryGroupList(params);
        
        params.put("getFieldAttributesType", "export");
    	List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<ProductXP> util = new ExportExcelUtils<ProductXP>(moduleTable,new ProductXP());
        return util.exportExcel(list, fieldList, "选品整单数据", "export");
    }

    /**
     * 导出Excel导入模板
     * @param params
     * @return
     * @throws Exception
     * @author DH-Xxj
     */
    @RequiresPermissions("business:productxp:import")
    @Log(title = "选品数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/exporttemplate")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult exportTemplate(@RequestParam Map<String, Object> params) throws Exception {
		params.put("moduleTable", moduleTable);
    	params.put("entity", new ProductXP()); 
    	
    	params.put("getFieldAttributesType", "template");
    	List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<ProductXP> util = new ExportExcelUtils<ProductXP>(moduleTable,new ProductXP());
        return util.exportExcel(null, fieldList, "选品导入模板", "template");
    }
    
	/**
	 * 保存数据
	 * @param infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
	 * @param infoItems 必要参数：对应实体类的json格式字符串
	 * @return
	 * @author DH-Xxj
	 */
    @RequiresPermissions(value={"business:productxp:add","business:productxp:edit","business:productxp:delete"},logical=Logical.OR)
    @Log(title = "选品", businessType = BusinessType.UPDATE)
    @PostMapping("/editpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult editSave(@RequestParam Map<String, Object> params){
		params.put("moduleTable", moduleTable);
    	AjaxResult ajaxResult = new AjaxResult();   
        try {
            ajaxResult= businessService.saveData(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }
    
	/**
	 * 保存数据
	 * @param infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
	 * @param infoItems 必要参数：对应实体类的json格式字符串
	 * @return
	 * @author XDH
	 */
    @GetMapping("/editpostLocal")
    @ResponseBody
    public AjaxResult editpostLocal(){

    	AjaxResult ajaxResult = new AjaxResult();

        try {
	    	List<List<String>> rows = ReadExcel.getRowsByFile("d:\\Users\\Administrator\\Desktop\\导入ERP\\20230224商品选品归属修改数据-第二批.xlsx", 0);
	    	
	    	// 重新整理的编码MAP
        	Map<String, List<List<String>>> GSBM_DHBM_ROWS_MAP = new HashMap<String, List<List<String>>>();
	        for (int i = 1; i < rows.size(); i++) {
	        	List<String> row = rows.get(i);
	        	String GSBM_DHBM = row.get(1);
	        	
	        	if (GSBM_DHBM_ROWS_MAP.containsKey(GSBM_DHBM)) {

		        	List<List<String>> rowsIn = GSBM_DHBM_ROWS_MAP.get(GSBM_DHBM);
		        	rowsIn.add(row);
		        	GSBM_DHBM_ROWS_MAP.put(GSBM_DHBM, rowsIn);
				} else {
		        	List<List<String>> rowsIn = new ArrayList<List<String>>();
		        	rowsIn.add(row);
		        	GSBM_DHBM_ROWS_MAP.put(GSBM_DHBM, rowsIn);
				}
	        }
	        
	        // 遍历MAP
	        for(Entry<String, List<List<String>>> e : GSBM_DHBM_ROWS_MAP.entrySet()) {
	        	
	        	String gsbm_dhbm = e.getKey();
	        	String gsbm = gsbm_dhbm;
	        	
	            OperateCompanyApply operateCompanyApply = operateCompanyApplyService.findByGsbm(gsbm);
	            if (operateCompanyApply == null) {
					continue;
				}

				
	        	Map<String, Object> params = new HashMap<String, Object>();
	            params.put("moduleTable", moduleTable);
	            
	        	JSONObject infoJO = new JSONObject();
	        	infoJO.put("createTime", DateUtil.getYYYY_MM_DD_HH_mm_ss(new Date()));
	        	infoJO.put("cidName", "福建省逸思信息科技有限公司");
	        	infoJO.put("cid", "C101");
	        	infoJO.put("vGsMc", operateCompanyApply.getvGsMc());
	        	infoJO.put("vGsJc", operateCompanyApply.getvGsJc());
	        	infoJO.put("vGsBm", operateCompanyApply.getvGsBm());
	        	infoJO.put("sUserName", "初始数据导入");
	        	infoJO.put("sUser", "09933");
	        	infoJO.put("sDeptName", "数智化事业部");
	        	infoJO.put("sDept", "C101.D101");
	        	infoJO.put("sPosition", "数智中心专员");
	        	infoJO.put("nid", "0");
	        	infoJO.put("effectStock", "");
	        	infoJO.put("activeFlow", "");
	        	infoJO.put("procInstId", "");
	        	infoJO.put("bUser", "09933");
	        	infoJO.put("bDept", "C101.D101");
	        	infoJO.put("aUserName", "初始数据导入");
	        	infoJO.put("aUser", "09933");
	        	infoJO.put("aDeptName", "数智化事业部");
	        	infoJO.put("aDept", "C101.D101");
	        	infoJO.put("aPosition", "数智中心专员");
	        	infoJO.put("activeFlowName", "准备制单");
	        	infoJO.put("bUserName", "初始数据导入");
	        	infoJO.put("bDeptName", "数智化事业部");
	        	infoJO.put("bPosition", "数智中心专员");
	        	params.put("infoMap", infoJO.toJSONString());

	        	List<List<String>> rowsIn = e.getValue();
	        	
	        	boolean isContinue = false;
	        	JSONArray infoItemsJA = new JSONArray();
				for (int j = 0; j < rowsIn.size(); j++) {
		        	List<String> rowIn = rowsIn.get(j);
		        	
		        	ProductBasis productBasis = productBasisService.queryProductBasisByCode(rowIn.get(0));
		        	if (productBasis == null) {
						continue;
					}
		        	
		        	ProductXP productXP = businessService.queryByGsbmAndCode(operateCompanyApply.getvGsBm(), rowIn.get(0));
		        	if (productXP != null) {
		        		isContinue = true;
		        		break;
					}
		        	JSONObject infoItemJO = new JSONObject();
		        	infoItemJO.put("fSpFwf", productBasis.getPriceService());
		        	infoItemJO.put("fMllH", productBasis.getfMllH());
		        	infoItemJO.put("sizeHeightJP", productBasis.getSizeHeightJP());
		        	infoItemJO.put("fYjb", productBasis.getfYjb());
		        	infoItemJO.put("codeMerge", productBasis.getCodeMerge());
		        	infoItemJO.put("fMllK", productBasis.getfMllK());
		        	infoItemJO.put("linkJP", productBasis.getLinkJP());
		        	infoItemJO.put("titleJP", productBasis.getTitleJP());
		        	infoItemJO.put("sizeLengthJP", productBasis.getSizeLengthJP());
		        	infoItemJO.put("nameUnit", productBasis.getNameUnit());
		        	infoItemJO.put("fTcbK", productBasis.getfTcbK());
		        	infoItemJO.put("fTcbH", productBasis.getfTcbH());
		        	infoItemJO.put("combination", productBasis.getCombination());
		        	infoItemJO.put("sizeWeightJP", productBasis.getSizeWeightJP());
		        	infoItemJO.put("vSfJp", productBasis.getvSfJp());
		        	infoItemJO.put("fCbK", productBasis.getfCbK());
		        	infoItemJO.put("fCbH", productBasis.getfCbH());
		        	infoItemJO.put("fWlYgFy", productBasis.getfWlYgFy());
		        	infoItemJO.put("rankThreeJP", productBasis.getRankThreeJP());
		        	infoItemJO.put("sizeWeight", productBasis.getSizeWeight());
		        	infoItemJO.put("name", productBasis.getName());
		        	infoItemJO.put("sizeWidthJP", productBasis.getSizeWidthJP());
		        	infoItemJO.put("rankOneJP", productBasis.getRankOneJP());
		        	infoItemJO.put("fYgFy", productBasis.getfYgFy());
		        	infoItemJO.put("img", productBasis.getImg());
		        	infoItemJO.put("code", productBasis.getCode());
		        	infoItemJO.put("iid", j + 1);
		        	infoItemJO.put("remark", productBasis.getRemark());
		        	infoItemJO.put("fJySj", productBasis.getfJySj());
		        	infoItemJO.put("ratingJP", productBasis.getRatingJP());
		        	infoItemJO.put("asinJP", productBasis.getAsinJP());
		        	infoItemJO.put("priceService", productBasis.getPriceService());
		        	infoItemJO.put("pGuid", productBasis.getGuid());
		        	infoItemJO.put("sizeHeight", productBasis.getSizeHeight());
		        	infoItemJO.put("sizeLength", productBasis.getSizeLength());
		        	infoItemJO.put("rankTwoJP", productBasis.getRankTwoJP());
		        	infoItemJO.put("remarkJP", productBasis.getRemarkJP());
		        	infoItemJO.put("codeHs", productBasis.getCodeHs());
		        	infoItemJO.put("dayOnJP", productBasis.getDayOnJP());
		        	infoItemJO.put("sizeWidth", productBasis.getSizeWidth());
		        	infoItemJO.put("scoreJP", productBasis.getScoreJP());
		        	infoItemJO.put("priceIn", productBasis.getPriceIn());
		        	infoItemJO.put("priceJP", productBasis.getPriceJP());
		        	infoItemJO.put("linkIn", productBasis.getLinkIn());
		        	infoItemJO.put("isSuperior", "否");
		        	infoItemsJA.add(infoItemJO);
				}
	            
				if (isContinue == true) {
					continue;
				} else {
		        	params.put("infoItems", infoItemsJA.toJSONString());
		            ajaxResult= businessService.saveData(params);
				}
	            
	        }
    	
        }catch (Exception e) {
        	e.printStackTrace();
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        
        return ajaxResult;
    }

    /**
     * 流转
	 * @param infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
	 * @param infoItems 必要参数：对应实体类的json格式字符串（仅需 guid）
     * @return
     * @author DH-Xxj
     */
    @RequiresPermissions("business:productxp:flow")
    @Log(title = "选品", businessType = BusinessType.FLOWGO)
    @PostMapping("/flowgopost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult flowGoSave(@RequestParam Map<String, Object> params){    	
		params.put("moduleTable", moduleTable);
    	AjaxResult ajaxResult = new AjaxResult();   
        try {
            ajaxResult= businessService.updateFlowGo(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     * 本地批量流转，
     * ！！！！！！！注意，使用前需要把结算资金的触发器禁用！！！！！！！
     */
    @GetMapping("/flowgopostLocal")
    @ResponseBody
    public AjaxResult flowgopostLocal(){
    	
    	for (; ;) {
        	List<String> listBid = businessService.listBidFlowZd();
    		
        	for(String bid : listBid) {
        		try {
            		System.out.println("bid---" + bid);
            		businessService.updateFlowGoPass(bid);
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
        	}
        	
        	if (listBid == null || listBid.size() == 0) {
				break;
			}
		}
        return AjaxResult.success();
    }

    /**
     * 退回
	 * @param infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
	 * @param infoItems 必要参数：对应实体类的json格式字符串（仅需 guid）
     * @return
     * @author DH-Xxj
     */
    @RequiresPermissions("business:productxp:flow")
    @Log(title = "选品", businessType = BusinessType.FLOWBACK)
    @PostMapping("/flowbackpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult flowBackSave(@RequestParam Map<String, Object> params){		
		params.put("moduleTable", moduleTable);
    	AjaxResult ajaxResult = new AjaxResult();    	
        try {
            ajaxResult= businessService.updateFlowBack(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }
}
